package com.shxt.service;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.shxt.data.D_User_GroupMapper;
import com.shxt.pojo.D_User_Group;

public class D_User_GroupService implements D_User_GroupMapper {
	
	private static D_User_GroupService instance = null ;
	
	public static D_User_GroupService getInstance(){
		if(instance==null){
			instance = new D_User_GroupService();
		}
		return instance;
	}

	@Override
	public int addUserGroup(D_User_Group dug) {
		SqlSession session = MyFactory.sessionFactory().openSession();
		int i = 0;
		try{
			D_User_GroupMapper dugm = session.getMapper(D_User_GroupMapper.class);
			dugm.addUserGroup(dug);
			i++;
			session.commit();
		}finally{
			if(session!=null){
				session.close();
			}
		}
		return i;
	}

	@Override
	public int updateUserGroup(D_User_Group dug) {
		SqlSession session = MyFactory.sessionFactory().openSession();
		int i = 0;
		try{
			D_User_GroupMapper dugm = session.getMapper(D_User_GroupMapper.class);
			dugm.updateUserGroup(dug);
			i++;
			session.commit();
		}finally{
			if(session!=null){
				session.close();
			}
		}
		return i;
	}

	@Override
	public List<D_User_Group> selectUserGroup() {
		SqlSession session = MyFactory.sessionFactory().openSession();
		List<D_User_Group> ldug ;
		try{
			D_User_GroupMapper dugm = session.getMapper(D_User_GroupMapper.class);
			ldug = dugm.selectUserGroup();
		}finally{
			if(session!=null){
				session.close();
			}
		}
		return ldug;
	}

}
